package com.teampuzzle;


import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;


import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

public class TeampuzzleActivity extends Activity {
    /** Called when the activity is first created. */

	public ImageButton startGameButton;
	public ImageButton optionButton;
	public ImageButton endGameButton;
	public static int displayWidth;
	public static int displayHeight;
	private static final String TAG = "MyActivity";
	private static final int SCREEN_ORIENTATION_PORTRAIT = 1;
	
    
	
	  @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        // requesting to turn the title OFF
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        // making it full screen
	        setRequestedOrientation(TeampuzzleActivity.SCREEN_ORIENTATION_PORTRAIT);
	        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        // set our MainGamePanel as the View
	        DisplayMetrics metrics = new DisplayMetrics();
			getWindowManager().getDefaultDisplay().getMetrics(metrics);
			displayWidth = metrics.widthPixels;
	    	displayHeight = metrics.heightPixels;
	    	
	    	//L�ser orientation till portrait
	        startMenu();
 
	    }



	private void startMenu() {
		// TODO Auto-generated method stub
		setContentView(R.layout.menu);
        startGameButton = (ImageButton)findViewById(R.id.startGame);
        endGameButton = (ImageButton)findViewById(R.id.endGame);
        
        startGameButton.setOnTouchListener(new OnTouchListener()
		{
		    public boolean onTouch(View v, MotionEvent event)
		    {
		        if(event.getAction() == MotionEvent.ACTION_DOWN)
		        {
		        	Log.d("button event","StartGame");
		        	startGame();
		        
		        }
		        return false;
		    }
		});
        
        
        
        endGameButton.setOnTouchListener(new OnTouchListener()
		{
		    public boolean onTouch(View v, MotionEvent event)
		    {
		        if(event.getAction() == MotionEvent.ACTION_DOWN)
		        {
		        	Log.d("button event","Exit");
		        	onDestroy();
		        	
		        }
		        return false;
		    }

		});
		
		//startGame();
		
	}

	private void startGame() {
		// TODO Auto-generated method stub
		
		Log.d("Hej", "STARTGAME");

		 setContentView(new GameView(this));
	     Log.d(TAG, "View added");
       
	}
	
  
	@Override
	protected void onDestroy() {
		Log.d(TAG, "Destroying...");
		super.onDestroy();
		
		GameThread.running = false;	
		finish();
	}

	@Override
	protected void onStop() {
		Log.d(TAG, "Stopping...");
		super.onStop();
	}
	
	//Ser till att spelet stoppas om man trycker p� "back"
	@Override
	protected void onPause() {
		Log.d(TAG, "Pausing...");
		super.onPause();
		
		GameThread.running = false;	
	}
	
	
	
    
	/*@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }*/
    
    //GameView mGameView;
	//GameThread mGameThread;
	//DisplayMetrics metrics;
	/* 
	 * Knappar
	 */
	
	
	
}